package com.example.studyflow.uploadfile;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author: hanll
 * @ClassName: TestController
 * @Date: 2022-10-17 14:01
 * @Version: 1.0
 * @Description:
 */
@RestController
@RequestMapping("/upload")
public class TestController {

    @PostMapping("/file")
    public void upload(@RequestParam("file") MultipartFile file) throws IOException {
        File path = new File("E:\\fileFlow\\"+file.getOriginalFilename());
        byte [] bytes = file.getBytes();
        FileOutputStream fileOutputStream = new FileOutputStream(path);
        fileOutputStream.write(bytes, 0, bytes.length);
        fileOutputStream.close();
    }
}
